package com.zdsoft.blp.zongbuju.shouye.bianmin.activity;

import android.content.Intent;

import android.graphics.Paint;
import android.text.Html;
import android.widget.TextView;

import com.zdsoft.blp.R;
import com.zdsoft.blp.gongyong.API.API;
import com.zdsoft.blp.gongyong.fanhui.FanHuiView;
import com.zdsoft.blp.gongyong.imageFrame.IvFrameView;
import com.zdsoft.blp.gongyong.net.BaseActivity;
import com.zdsoft.blp.gongyong.net.Net;
import com.zdsoft.blp.gongyong.net.NetCallback;
import com.zdsoft.blp.zongbuju.shouye.taoshihui.entity.Goods;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2016/9/12.
 */
public class BMspxqActivity extends BaseActivity implements NetCallback{
    private FanHuiView fh;
    private IvFrameView iv;
    private TextView tv_xPrice,tv_yPrice,tv_merchantName,
            tv_address,tv_goodsName,tv_summary,tv_infoTitle,tv_infoContent;
    private List<Goods>list;
    private Goods goods;
    private String summary,oldPrice,merchantAddr,discountPrice,picPath,content,
            title,merchantName,goodsName;


    @Override
    protected void init() {
        setContentView(R.layout.xq_zbyh);
        fh=find(R.id.fh);
        fh.getTv_title().setText("商品详情");
        iv=find(R.id.iv);

        tv_xPrice=find(R.id.tv_xPrice);
        tv_yPrice=find(R.id.tv_yPrice);
        tv_merchantName=find(R.id.tv_merchantName);
        tv_address=find(R.id.tv_address);
        tv_goodsName=find(R.id.tv_goodsName);
        tv_summary=find(R.id.tv_summary);
        tv_infoTitle=find(R.id.tv_infoTitle);
        tv_infoContent=find(R.id.tv_infoContent);

        Intent intent=getIntent();
        String id=intent.getStringExtra("id");

        Net net=new Net();
        net.url = API.GOODS_URL;
        net.nameSpace = API.GOODS_NAMESPACE;
        net.methodName = API.GOODSCONTENT;
        Map<String,Object> map=new HashMap<>();
        map.put("id",id);
        //net.code=1;
        net.parms=map;
        getServer(net,this);

    }

    @Override
    public void onResponse(boolean flag, int code, String res) {
       if (flag){
           try {
               JSONObject object = new JSONObject(res);
                summary=object.getString("summary");
                oldPrice=object.getString("oldPrice");
                merchantAddr=object.getString("merchantAddr");
                discountPrice=object.getString("discountPrice");
               JSONArray array = object.getJSONArray("picPathSet");
               List<String>picList=new ArrayList<>();
               for (int i = 0; i < array.length(); i++) {
                   JSONObject jsonObject = array.getJSONObject(i);
                    picPath=jsonObject.getString("picPath");
                   picList.add(picPath);
               }
               JSONArray array2 = object.getJSONArray("details");
               for (int j = 0; j < array2.length(); j++) {
                   JSONObject jsonObject2 = array2.getJSONObject(j);
                  content=jsonObject2.getString("content");
                    title=jsonObject2.getString("title");
               }
                merchantName=object.getString("merchantName");
                goodsName=object.getString("goodsName");

               //给控件赋值
               iv.show(picList);
               tv_xPrice.setText(discountPrice);
               tv_yPrice.setText(oldPrice+"元");
               tv_yPrice.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
               tv_merchantName.setText(merchantName);
               tv_address.setText(merchantAddr);
               tv_goodsName.setText(goodsName);
               tv_summary.setText(summary);
               tv_infoTitle.setText(title);
               tv_infoContent.setText(Html.fromHtml(content));

           } catch (JSONException e) {
               e.printStackTrace();
           }
       }
    }


}
